<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>广东省传播平台-项目库录入页</title>
	<link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
		<link href="<%=path%>/js/My97DatePicker/skin/WdatePicker.css"
			rel="stylesheet" type="text/css" />
				<style>
		#organizesTree {
			margin-top: 10px;
			border: 1px solid #617775;
			background: #f0f6e4;
			min-width: 180px;
			max-height: 400px;
			overflow-y: scroll;
			overflow-x: auto;
		}
		</style>
        <link type="text/css" rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css" />	
		<link type="text/css" href="<%=path%>/js/jquery-ui-1.8.21.custom/css/smoothness/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
		<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.1.js"></script>
		<script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.1.min.js"></script>
		<script type="text/javascript" src="<%=path%>/js/jquery.ztree.exedit-3.1.min.js"></script>
		<script type="text/javascript" src="<%=path%>/js/form.js"></script>
		<script type="text/javascript" src="js/My97DatePicker/WdatePicker.js"></script>
		<script type="text/javascript" src="<%=path%>/js/jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js"></script>
		<script type="text/javascript" src="<%=path%>/js/public.js"></script>
		<script type="text/javascript">
	$(document).ready(function(){  
   //禁止退格键 作用于Firefox、Opera    
    document.onkeypress = banBackSpace;  
   //禁止退格键 作用于IE、Chrome   
	  document.onkeydown = banBackSpace;  
	});
	//处理键盘事件 禁止后退键（Backspace）密码或单行、多行文本框除外 
	function banBackSpace(e){
		//alert(event.keyCode)
	    var ev = e || window.event;//获取event对象   
	    var obj = ev.target || ev.srcElement;//获取事件源     
	    var t = obj.type || obj.getAttribute('type');//获取事件源类型     
	    //获取作为判断条件的事件类型 
	    var vReadOnly = obj.readOnly;
	    var vDisabled = obj.disabled;
	    //处理undefined值情况 
	    vReadOnly = (vReadOnly == undefined) ? false : vReadOnly;
	    vDisabled = (vDisabled == undefined) ? true : vDisabled;
	    //当敲Backspace键时，事件源类型为密码或单行、多行文本的，  
	    //并且readOnly属性为true或disabled属性为true的，则退格键失效  
	    var flag1 = ev.keyCode == 8 && (t == "password" || t == "text" || t == "textarea") && (vReadOnly == true || vDisabled == true);
	    //当敲Backspace键时，事件源类型非密码或单行、多行文本的，则退格键失效    
	    var flag2 = ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea";
	    //判断    
	    if (flag2 || flag1) 
	        event.returnValue = false;//这里如果写 return false 无法实现效果 
	}
</script>
	<script type="text/javascript">
	
	//获取后台数据显示组织架构
	var organizes =${flag};
	
	//组织架构初始化
	var organizeSetting = {
		view : {
			dblClickExpand : false
		},
		data : {
			simpleData : {
				enable : true
			}
		},
		callback : {
			beforeClick : beforeClick,
			onClick : organizeOnClick
		}
	};

	//点击事件
	function beforeClick(treeId, treeNode) {
		var check = (treeNode && !treeNode.isParent);
		if (!check)
			alert("出现没有选择的！呼呼、、、");
		return check;
	}

	//组织架构点击事件
	function organizeOnClick(e, treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("organizesTree"), nodes = zTree.getSelectedNodes(), v = "";
		nodes.sort(function compare(a, b) {
			return a.id - b.id;
		});
		for ( var i = 0, l = nodes.length; i < l; i++) {
			v += nodes[i].name + ",";
		}
		if (v.length > 0)
			v = v.substring(0, v.length - 1);
		var orgNameObj = $("#showOrganize");
		orgNameObj.attr("value", v);
		//设置隐藏域中组织编号  
		$('#orgID').val(treeNode.id);
		hideMenu('organizeContent');
	}

	//隐藏组织架构
	function hideMenu(divId) {
		$("#" + divId).fadeOut("fast");
		$("body").unbind("mousedown", {
			tempDiv : divId
		}, onBodyDown);
	}

	//组织架构弹出窗
	function showMenu(objId, divId) {
		var cityObj = $("#" + objId);
		var cityOffset = $("#" + objId).position();
		$("#" + divId).css( {
			left : cityOffset.left + "px",
			top : cityOffset.top + cityObj.outerHeight() + "px"
		}).slideDown("fast");
		$("body").bind("mousedown", {
			tempDiv : divId
		}, onBodyDown);
	}
	
	//鼠标点击别的地方隐藏弹出属性菜单
	function onBodyDown(event) {
		var divId = event.data.tempDiv;
		if (!(event.target.id == "showOrganize" || $(event.target).parents(
				"#" + divId).length > 0)) {
			hideMenu(divId);
		}
	}
	
	function regcheck()
	{
	   var myReg = /^[^@\/\'\\\"#$%&\^\*<>]+$/;
       var contractNum = /^[\w-\s]+$/;
       var contractWord = /^\x00-\xff/;
       var timeReg= /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})/;
       
       //var projectid = document.getElementById('proId').value;
       var projectname = document.getElementById('projectName').value;
       var start = document.getElementById('beginTime').value;
       var end = document.getElementById('endTime').value;

	    if(!myReg.test(projectname))
	    {
	        alert("项目名称不能包含特殊字符！");
			return false;
	    }
	    if(!timeReg.test(start))
	    {
           alert('开始时间日期格式错误');
           return false;
	    }
	    if(!timeReg.test(end))
	    {
	       alert('结束时间日期格式错误');
	       return false;
		}
	    return true;
	}
	
	function checkValue1()
    {
       var flag = false;
       $('input:text').each(function(i){
          if(this.value == null || $.trim(this.value)=="")
          {
             this.focus();
             if(i==0)
             {
            	 alert('项目名称不能为空');
             }
             if(i==1)
             {
            	 alert('开始时间不能为空');
             }
             if(i==2)
             {
            	 alert('结束时间不能为空');
             }
             //alert('必填项不能为空');
             //$("#Tip"+i).html("<span style='color:red;'>不能为空！</span>");
             flag = false;
             return false;
          }
          else
          {
             //$("#Tip"+i).html("");
             flag = true;
          }
       });
       return flag;
    }
    
    function checkValue2()
    {
        var flag = false;
        $('select').each(function(i){
	          if(this.value == null || this.value=="")
	          {
	             this.focus();
	             alert('请选择相关类型');
	             //$('#projectTypeTip').html("<span style='color:red;'>请选择相关类型</span>");
	             flag = false;
                 return false;
	          }
	          else
	          {
	             //$('#projectTypeTip').html("");
	             flag = true;
	          }
	       });
	     return flag;
    }
    
        function getBack()
		{
		   if(confirm('您确认取消本次操作？'))
		   {
		      window.history.go(-1);
		   }
		}
		function doSubmit(oldName) 
		{
			var projectName = $("#projectName").val();
			
			if (checkValue1()&&checkValue2())
			{
			    if(regcheck())
			    {
				    if($.trim(projectName)!=oldName)
					{
					  $.getJSON("proisExist.action", {'project.projectName': $.trim(projectName), time : new Date().getTime()} ,function(data){
			             if(data.rsflag)
			             {
			                alert("项目名称已存在，请重新输入。");
			                $("#projectName").focus();
			                return false;
			             }
			             else
			             {
			                document.getElementById("form1").action = "proMod.action";
					        document.getElementById("form1").submit();
			             }
			          });
					}
					else
					{
				        document.getElementById("form1").action = "proMod.action";
				        document.getElementById("form1").submit();
					}
			    }
			}
			
		}
		
		$(document).ready(function(){
			//selectNav('nav3');
				//设置组织架构弹出框
			$.fn.zTree.init($("#organizesTree"), organizeSetting, organizes);
		});
		
	</script>
</head>

<body>
	<!-- 顶栏start -->
	<jsp:include page="../common/top.jsp"></jsp:include>
	<!-- 顶部end -->
<!-- 顶部start -->
<div id="main">
	<div class="body">
		<jsp:include page="../common/nav.jsp"></jsp:include>
		<!-- 主体 -->
		<div class="main_body">
			<form id="form1" action="proAdd.action" method="post">
			<div id="add_div">
				<input type="hidden" name="project.projectSection" value="${project.projectSection}"/>
				<input type="hidden" name="project.projectDepartment" value="${project.projectDepartment}"/>
				<input type="hidden" name="project.projectManager" value="${project.projectManager}"/>
				<input type="hidden" name="project.city" value="${project.city}"/>
				<input type="hidden" name="project.projectId" value="${project.projectId}" />
				<table class="table_add" style="width:100%;" align="center">
					<tr>
						<th style="width:150px;">项目编号：</th>
						<td style="width:250px;">
							<label><s:property value="#request.project.projectId" /></label>
						</td>
						<td width="150px;">
							
						</td>
						<th style="width:189px;">项目名称：</th>
						<td>
							<input type="text" class="text" id="projectName" name="project.projectName" style="width:225px;"  value="${project.projectName}" maxlength="60"/>
							&nbsp;<span style='color:red;'>*</span>					
						</td>
						<td width="150px;">
							<div id="Tip0" class="Tip0"></div>
						</td>
					</tr>
					<tr>
						<th style="width:150px;">开始时间：</th>
						<td style="width:250px;">
							<input type="text" id="beginTime" class="text Wdate" name="projectStartTime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'endTime\')||\'9999-12-31\'}'})" style="width:225px;" value="<fmt:formatDate value='${project.projectStartTime}' pattern='yyyy-MM-dd'/>"/>
							&nbsp;<span style='color:red;'>*</span>						
						</td>
						<td width="150px;">
							<div id="Tip1" class="Tip1"></div>
						</td>
						<th style="width:189px;">结束时间：</th>
						<td>
							<input type="text" id="endTime" class="text Wdate" name="projectEndTime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'beginTime\')||\'0000-12-31\'}'})" style="width:225px;"  value="<fmt:formatDate value='${project.projectEndTime}' pattern='yyyy-MM-dd'/>"/>
							&nbsp;<span style='color:red;'>*</span>					
						</td>
						<td width="150px;">
							<div id="Tip2" class="Tip2"></div>
						</td>
					</tr>
					<tr>
						<th style="width:150px;">项目类型：</th>
						<td style="width:250px;">
							<s:select id="typelist" name="project.projectType" list="typelist" listKey="id" listValue="datavalue" headerKey="" headerValue="--项目类型--" cssStyle="width:225px;"></s:select>
							&nbsp;<span style='color:red;'>*</span>							
						</td>
						<td width="150px;">
							<div id="projectTypeTip"></div>
						</td>
						<th style="width:189px;"></th>
						<td>
							<!--  <input type="text" id="begTime" class="text Wdate" name="arrangeTime" onfocus="WdatePicker({dateFmt:'yyyy-MM'})" style="width:225px;" value="<fmt:formatDate value='${project.arrangeTime}' pattern='yyyy-MM'/>"/>
							&nbsp;<span style='color:red;'>*</span>-->						
						</td>
						<td width="150px;">
							
						</td>
					</tr>
					

					<tr>
						<th style="width:150px;">项目描述：</th>
						<td colspan="6" style="width:225px;">
							<textarea rows="4" cols="120" name="project.projectDesciption" onkeyup="if(this.value.length >80) this.value=this.value.substr(0,80);">${project.projectDesciption}</textarea>
						</td>
					</tr>
				</table>
			</div>
			</form>
			<div style="margin:8px 0 0 150px;">
				<input type="button" class="btn-title" value="填写完成，提交"  onclick="doSubmit('${project.projectName}');"/>
				&nbsp;&nbsp;
				<input type="button" class="btn-title" value="取消"  onclick="getBack();"/>
			</div>
		</div>
		<div id="menuContent" style="background-color:#f0f6e4;display:none; position: absolute;">
	<ul id="treeDemo" class="ztree" style="margin-top:0; width:220px;"></ul>
</div>
	</div>
	
</div>
<div id="organizeContent" class="menuContent"
	style="display: none; position: absolute;">
	<ul id="organizesTree" class="ztree" style="margin-top: 0;"></ul>
</div>
<!-- 顶部end -->
<!-- 底部start -->
<jsp:include page="/jsp/common/bottom.jsp"></jsp:include>
<!-- 底部end -->
</body>
</html>
